<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>产品采购管理</title>
</head>
<body>
<style type="text/css">
</style>
<script>
    $(function () {
        $("tboby tr").addClass("datagrid-row");
        $("#purdg").datagrid({
            onLoadSuccess:function (data) {
                $("a[name='details']").linkbutton({
                    width:30,iconCls:'icon-my_detail',plain:true
                });
                $("a[name='delete-one-pur']").linkbutton({
                    onClick: function () {
                        var rowId = $(this).attr("id").substring(6);
                        $.messager.confirm("继续删除提示", "确定要删除选定的采购单吗？", function (a) {
                            if (a) {
                                $.post("pro-purchases-del", {rowsId: rowId}, function (r) {
                                    if (r.success) {
                                        $.messager.alert("SUCCESS", "删除成功！", "info");
                                        $("#purdg").datagrid({
                                            url:'allPurPaged',
                                            method:'post'
                                        });
                                        $("#purdg").datagrid("reload");
                                    } else {
                                        $.messager.alert("Failed", r.message, "error");
                                    }
                                });
                            }
                        });
                    },
                    width:30,iconCls:'icon-my_delete',plain:true
                });
                $("a[name='edit']").linkbutton({
                    width:30,iconCls:'icon-my_edit',plain:true
                });

            }
        });
        $("#reloadAllPur").linkbutton({
            onClick:function () {
                $("#purdg").datagrid({
                    url:'allPurPaged',
                    method:'post'
                });
                $("#purdg").datagrid("reload");
            }
        });
        //删除选中的分类(批量删除)
        $("#pur-del-btn").linkbutton({onClick:function (){
                var rowsId = "";
                var rows = $("#purdg").datagrid('getSelections');
                if(rows.length>=1){
                    $.messager.confirm("继续删除提示","确定要删除选定的这些采购单吗？",function (t) {
                        if(t){
                            for(var i =0; i<rows.length;i++){
                                if(i==0){
                                    rowsId=rowsId+rows[i].purid;
                                }else {
                                    rowsId=rowsId+","+rows[i].purid;
                                }

                            }
                            $.post("pro-purchases-del",{rowsId:rowsId},function (r) {
                                if(r.success){
                                    $.messager.alert("SUCCESS","删除成功！","info");
                                    $("#purdg").datagrid({
                                        url:'allPurPaged',
                                        method:'post'
                                    });
                                    $("#purdg").datagrid("reload");
                                }else{
                                    $.messager.alert("Failed",r.message,"error");
                                }
                            });
                        }
                    });

                }else{
                    $.messager.alert("错误信息","未选中行！！！",'warning');
                }
            }});
    });
    function format(value,row,index){
        if(row.purstatus=="待采购"){
            var str='<a id = \"'+"purShow"+row.purid+'\" name="details" href="#" onclick="createDialogHut(\'detilsPur'+row.purid+'\',\'查看采购详情\',\'to-form-pur-details\','+row.purid+')" class="easyui-linkbutton edit-btn"></a>'+
                '<a id =\"'+"purDel"+row.purid+'\" name="delete-one-pur" href="#"  class="easyui-linkbutton edit-btn"></a>'+
                '<a id = \"'+"purUpdate"+row.purid+'\" name="edit" href="#" onclick="createDialogHut(\'editPur'+row.purid+'\',\'编辑采购信息\',\'to-form-pur-update\','+row.purid+')" class="easyui-linkbutton edit-btn"></a>';
            return str;
        }else{
            return '<a id = \"'+"purShow"+row.purid+'\" name="details" href="#" onclick="createDialogHut(\'detilsPur'+row.purid+'\',\'查看采购详情\',\'to-form-pur-details\','+row.purid+')" class="easyui-linkbutton edit-btn"></a>';
        }
    }
    function formatM(value,row,index){
        if(value!=null){
            return '<b style="color:red;">'+"￥"+value+'</b>';
        }else{
            return value;
        }
    }
</script>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false">
        <table id="purdg" class="easyui-datagrid table-chance" style="width: auto;" data-options="fit:true,striped:true,height:350,fitColumns:true,
   autoRowHeight:true,nowrap:false,pagination:true,toolbar:'#tools-pur',
pageList:[5,10,15,20],pageSize:10,url:'allPurPaged',method:'post',scrollbarSize:0">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'code',width:5,align:'center',checkbox:true">编码</th>
                <th data-options="field:'purid',width:15,align:'center'">采购ID</th>
                <th data-options="field:'purnumber',hidden:true,width:15,align:'center'">采购单号</th>
                <th data-options="field:'purtheme',width:15,align:'center'">采购主题</th>
                <th data-options="field:'purdate',width:15,align:'center'">采购日期</th>
                <th data-options="field:'purexcepttime',width:15,align:'center'">预计到货日期</th>
                <th data-options="field:'purmoney',width:20,align:'center'" formatter='formatM'>采购金额</th>
                <th data-options="field:'clientId',width:10,hidden:true,align:'center'">客户/供应商id</th>
                <th data-options="field:'clientname',width:10,align:'center'">客户/供应商</th>
                <th data-options="field:'ioDispatherId',align:'center',hidden:true">联系人</th>
                <th data-options="field:'purUsername',width:10,align:'center'">经手人</th>
                <th data-options="field:'purstatus',width:15,align:'center'">采购状态</th>
                <th data-options="field:'manager',width:20,align:'center'" formatter="format">操作</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--工具栏-->
        <div id="tools-pur" style="height:10%;">
            <a href="#" id="pur-del-btn" class="easyui-linkbutton" data-options="iconCls:'icon-my_delete',plain:true">批量删除</a>
            <a  id="reloadAllPur" class="easyui-linkbutton" data-options="iconCls:'icon-my_search',plain:true">查询所有</a>

            <input id="pur-Search" class="easyui-searchbox" style="width: 35%;" data-options="searcher:function(value,name){
           $('#purdg').datagrid({
            url:'getAllPurchasesBymh',
            method:'post',
            queryParams:{q:value}
            });
            $('#pur-Search').searchbox('clear');
            $('#purdg').datagrid('reload');
           },prompt:'模糊查询采购主题或经手人名称'"/>
            <a href="#" onclick="createDialog('hlQueryPur','高级查询','to-form-pur-highLevel')" class="easyui-linkbutton">高级查询</a>
            <div style="text-align: right;height:5%;margin-right:8%;padding-bottom: 20px;">
                <a href="#" onclick="createDialog('newPur','新建采购单','to-form-pur-add')" class="easyui-linkbutton" data-options="iconCls:'icon-mini_add2',border:true">新建采购单</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>

